export const isFullscreen = () => {
	return (
		document.fullscreenElement ||
		document["msFullscreenElement"] ||
		document["mozFullScreenElement"] ||
		document["webkitFullscreenElement"] ||
		false
	)
}

export const isNotEmpty = (dataList) => {
    return dataList && dataList.length > 0;
}

export const getText = (value: any) => {
    return value ? value.toString() : '';
}

export const splitArray = (inputArray: Array<any>, step: number) => {
    const result = [] as Array<any>;
    if (isNotEmpty(inputArray)) { 
        for (let i = 0; i < inputArray.length; i += step) {
            result.push(inputArray.slice(i, i + step));
        }
    }
    return result;
}

// 秒数格式化函数
export const formatSeconds = (secondsStr: string): string => {
    const totalSeconds = Math.floor(parseFloat(secondsStr));
    
    const days = Math.floor(totalSeconds / 86400);
    const hours = Math.floor((totalSeconds % 86400) / 3600);
    const minutes = Math.floor((totalSeconds % 3600) / 60);
    const seconds = totalSeconds % 60;
    
    const parts = [] as string[];
    if (days > 0) parts.push(`${days}天`);
    if (hours > 0) parts.push(`${hours}时`);
    if (minutes > 0) parts.push(`${minutes}分`);
    if (seconds > 0) parts.push(`${seconds}秒`);

    return parts.length > 0 ? parts.join('') : '0秒';
};

// 格式化直播时间（将yyyy-mm-dd HH:MM:SS时间格式化为mm-dd HH:MM）
export const formatLiveTime = (dateTime: string): string => {
    if (!dateTime) return '';

    return dateTime.substring(5, 16);
}

export const getLocalUserInfo = () => {
    return JSON.parse(localStorage.getItem('userInfo') || '{}');
}

export const setLocalUserInfo = (userInfo: any) => {
    return localStorage.setItem('userInfo', JSON.stringify(userInfo || {}));
}

export const getLocalUserToken = () => {
    return localStorage.getItem('userToken') || '';
}

export const setLocalUserToken = (token: string) => {
    return localStorage.setItem('userToken', token || '');
}

// 获取URL带时间戳参数以解决缓存问题
export const getUrlWithTimestamp = (url: string) => {
    if (!url) return '';

    const timestamp = new Date().getTime();
    return url.indexOf('?') > 0 ? `${url}&t=${timestamp}` : `${url}?t=${timestamp}`;
}
